package put.cs.two.to.tsp.calculators.base;

import java.util.ArrayList;
import java.util.List;

import put.cs.two.to.tsp.io.NodeSetFileReader;
import put.cs.two.to.tsp.models.NodeSet;
import put.cs.two.to.tsp.models.TSPSolution;
import put.cs.two.to.tsp.models.TSPSolutionChangedEvent;

public abstract class AbstractExperiment {

    protected NodeSetFileReader reader;

    protected List<TSPSolutionChangedListener> listeners = new ArrayList<TSPSolutionChangedListener>();

    public abstract TSPSolution doWork(NodeSet nodeSet);

    public void addTSPSolutionChangedListener(TSPSolutionChangedListener listener) {
        listeners.add(listener);
    }

    public void removeTSPSolutionChangedListener(TSPSolutionChangedListener listener) {
        listeners.remove(listener);
    }

    protected void notifyListeners(TSPSolutionChangedEvent event) {
        for (TSPSolutionChangedListener listener : listeners) {
            listener.onTSPSolutionChanged(event);
        }
    }
}
